package com.tqfframe;

import com.tqfframe.bean.CustomBean;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @Author: 唐祺峰
 * @Date: 2022/3/11 0011 13:24
 * @Version 1.0
 */
public class ImportCustomBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        String simpleName = CustomBean.class.getName();
        //定义一个BeanDefinition
        RootBeanDefinition rootBeanDefinition = new RootBeanDefinition();
        rootBeanDefinition.setBeanClass(CustomBean.class);
        //初始化bean属性
        MutablePropertyValues propertyValues = new MutablePropertyValues();
        propertyValues.add("name", "唐祺峰");
        rootBeanDefinition.setPropertyValues(propertyValues);
        //注册进容器
        registry.registerBeanDefinition(simpleName, rootBeanDefinition);
    }
}
